import axios from 'axios'
// 获取token
function getToken ($this) {
  var token = ''
  var token1 = window.localStorage.getItem('token') // 缓存
  if($this.$route.query.token){
    var token2 = $this.$route.query.token// 地址栏
    localStorage.setItem('token',token2)
  }
  // var token3 = $this.$cookie.get('token')// cookie来的
  token = $this._globe.token || token2 ||token1 ||123456;
  if (!token) {
    // 你需要接受路由的参数再跳转
    $this.$router.push({
      path: '/'
    })
  } else {
    if (!token1) {
      window.localStorage.setItem('token', token)
    }
  }
  return token
}
function fail($this){
  $this.$router.push({
    path: '/login'
  })
}
// function goRequest ($this, $url, $params, $method, $header_type) {
//   // $header_type  1 ：
//   var token = getToken($this),
//   if ($header_type == 1) {
//     if($method=='post'){
//       axios({
//         url: $url,
//         method: $method,
//         data: $params
//       })
//         .then(function (res) {
//           if (res.data.code == 1) {
//             result = res.data
//             typeof callback === 'function' && callback.call(window, result)
//             return result;
//           } else if (res.data.code == -1) {
//             // 弹出消息
//           } else if (res.data.code == -2) {
//             // 登录失效
//             $this.$router.push({
//               path: '/'
//             })
//           }
//         })
//         .catch(function (res) {})
//     }else if($method=="get"){
//       axios({
//         url: $url,
//         method: $method,
//         params: $params
//       })
//         .then(function (res) {
//           if (res.data.code == 1) {
//             result = res.data
//             typeof callback === 'function' && callback.call(window, result)
//             return result
//           } else if (res.data.code == -1) {
//             // 弹出消息

//           } else if (res.data.code == -2) {
//             // 登录失效
//             $this.$router.push({
//               path: '/'
//             })
//           }
//         })
//         .catch(function (res) {})
//     }

//   } else {
//     axios({
//       url: $url,
//       method: $method,
//       params: $params,
//       headers: {'Content-Type': 'multipart/form-data'}
//     })
//       .then(function (res) {
//         if (res.data.code == 1) {
//           result = res.data
//           typeof callback === 'function' && callback.call(window, result)
//           return result
//         } else if (res.data.code == -1) {
//           // 弹出消息

//         } else if (res.data.code == -2) {
//           // 登录失效
//           fail($this);
//         }
//       })
//       .catch(function (res) {})
//   }
//   return result
// }
// function getWXcode($this){
//   axios({
//       url: "/super/index/Login/getwxcode",
//       method: "get",
//       params: {

//       }
//     })
//   .then(function(res) {
//       if (res.data.code == 1) {
//           location.href=res.data.data.url;
//       }else{
//           //
//       }
//   })
//   .catch(function(res) {});
  // let $header=null
  // request($this,$header,"/test/index/Login/getwxcode",'get',{})
// }
//获取验证码
function getCode($this){
  var time = Date.parse(new Date())/1000;
    axios({
        url: "/super/api/index/sendCode",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            type:2,
            phone: $this.phone,
        }
        })
    .then(function(res) {

        if (res.data.code == 1) {

        }else {
        }
    })
    .catch(function(res) {});
}
//登录
function getLogin($this){
  var time = Date.parse(new Date())/1000;
    axios({
        url: "/super/api/index/codeLogin",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            phone: $this.phone,
            code:$this.code,
            unionid:$this.unionid,
            openid:$this.openid,
        }
        })
    .then(function(res) {

        if (res.data.code == 1) {
          window.localStorage.setItem('token',res.data.data.token);
          $this.$router.push({
            path: '/'
          });
        }else{
          $this.$toast(res.data.message)
        }
    })
    .catch(function(res) {});
}
//热搜
function hotSearchTopTen($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
    axios({
        url: "/super/api/Home/hotSearchTopTen",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            token: token,
        }
        })
    .then(function(res) {

        if (res.data.code == 1) {
          $this.data=res.data.data
        }else if (res.data.code == -2) {
          // 登录失效
          fail($this);
        }
    })
    .catch(function(res) {});

}
//搜索商品
function searchGoods($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
    axios({
        url: "/super/api/goods/searchGoods",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            token: token,
            page:$this.page,
            keyword:$this.searchContent,
        }
        })
    .then(function(res) {
        if (res.data.code == 1) {
          $this.data=res.data.data;
          $this.searchList=$this.searchList.concat(res.data.data.list);
          $this.allPage=res.data.data.all_page;
          if(window.localStorage.getItem('searchGoods')){
            var searchGoods=JSON.parse(window.localStorage.getItem('searchGoods'));
            searchGoods.unshift($this.searchContent);
            searchGoods=new Set(searchGoods);
            window.localStorage.setItem('searchGoods',JSON.stringify(searchGoods));
            $this.nearest= JSON.parse(window.localStorage.getItem('searchGoods'));
          }else{
            window.localStorage.setItem('searchGoods',JSON.stringify([$this.searchContent]));
            $this.nearest=[$this.searchContent];
          }
          $this.loading=true;
        }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});

}
//搜索文章
function fullTextSearch($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  $this.isNone=false;
  $this.isrespose=false;
    axios({
        url: "/super/api/Home/fullTextSearch",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            token: token,
            page:$this.page,
            keyword:$this.searchContent,
            list:$this.list,
            type:$this.type,
        }
        })
    .then(function(res) {
      $this.isNone=true;
      $this.isrespose=true;
        if (res.data.code == 1) {
          $this.data=res.data.data;
          $this.searchList=$this.searchList.concat(res.data.data.list);
          if(res.data.data.count){
            $this.count=res.data.data.count;
          }

          $this.allPage=res.data.data.all_page;
          if(window.localStorage.getItem('searchGoods1')){
            var searchGoods=JSON.parse(window.localStorage.getItem('searchGoods1'));
            searchGoods.unshift($this.searchContent);
            searchGoods=new Set(searchGoods);
            window.localStorage.setItem('searchGoods1',JSON.stringify(searchGoods));
            $this.nearest= JSON.parse(window.localStorage.getItem('searchGoods1'));
          }else{
            window.localStorage.setItem('searchGoods1',JSON.stringify([$this.searchContent]));
            $this.nearest=[$this.searchContent];
          }
          $this.loading=true;
        }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});

}
function getFollowDetail($this,page){
    var time = Date.parse(new Date())/1000;let token = getToken($this);
    axios({
        url: "/super/api/Home/followDetail",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            token:token,
            article_id: $this.$route.query.article_id,
            page: page,
        }
        })
    .then(function(res) {

        if (res.data.code == 1) {
            $this.data=res.data.data;
            $this.category_id=res.data.data.category_id;
            getRecommendArticle($this)
        }else if (res.data.code == -2) {
          // 登录失效
          fail($this);
        }
    })
    .catch(function(res) {});
}
function getRecommendArticle($this){
    var time = Date.parse(new Date())/1000;let token = getToken($this);
    axios({
        url: "/super/api/Home/recommendArticle",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            token: token,
            category_id:$this.category_id,
            article_id:$this.$route.query.article_id,
            page:1
        }
        })
    .then(function(res) {

        if (res.data.code == 1) {
          $this.data1=res.data.data;
          $this.articleList=res.data.data.list;
          $this.getShopIndexucang = res.data.data;
          $this.pinlun = res.data.data;
          $this.dianzan = res.data.data;
          $this.kegoumai = res.data.data;
        }else if (res.data.code == -2) {
          // 登录失效
          fail($this);
        }
    })
    .catch(function(res) {});
}
function loadedRecommendArticle($this,loaded){
    var time = Date.parse(new Date())/1000;let token = getToken($this);
    $this.page++;
    axios({
        url: "/super/api/Home/recommendArticle",
        method: "post",
        data: {
            time: time,
            device_id: $this._globe.device_id,
            version: $this._globe.version,
            platform: $this._globe.platform,
            token: token ,
            category_id:$this.category_id,
            article_id:this.$route.params.articleId,
            page:$this.page
        }
        })
    .then(function(res) {

        if (res.data.code == 1) {
            res.data.data.list.forEach((v) => {
                $this.articleList.push(v);
            });
            if ($this.page <= $this.data1.all_page) {
                $this.commendList = this.commendList.concat($this.articleList);
                $this.BOTTOM_DEFAULT_CONFIG.doneText = $this.BOTTOM_DEFAULT_CONFIG.pullText;
                loaded("done");
              } else {
                $this.BOTTOM_DEFAULT_CONFIG.doneText = "内容已全部展示";
                //结束刷新功能
                loaded("done");
                $this.loaded = true;
              }
        }else if (res.data.code == -2) {
          // 登录失效
          fail($this);
        }
        if (res.data.code == 1) {
            $this.data1=res.data.data;
        }else {
        }
    })
    .catch(function(res) {});
}
function getProductsDetail($this) {
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/goods/goodsInfo",
    method: "post",
    data: {
      type:$this.$route.query.type,//this.$route.query.type
      group_id:$this.$route.query.group_id,//this.$route.query.group_id
      join_id:$this.$route.query.join_id,//this.$route.query.join_id
      limit_id:$this.$route.query.limit_id,//this.$route.query.limit_id
      goods_id:$this.$route.query.goods_id,//this.$route.query.goods_id
      activity_id:$this.activity_id,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      const data = res.data.data;
      $this.goodsInfo = data;
      $this.activitys_id = data.activity.activitys_id;
      $this.swipeImg = data.goods_imgs;
      $this.coupons = data.coupon;
      $this.time = data.time*1000;
      $this.isNew = data.is_new;
      $this.limit = data.limit;
      $this.activity = data.activity;
      $this.limitType = data.limit.limit_type;
      $this.group = data.group;
      $this.presale = data.is_presale;
      $this.buyLimit = data.limit.buy_limit;
      $this.is_join_group=data.group.is_join_group;
      $this.promise =data.promise;
      $this.type=data.type;
      $this.is_notice=res.data.data.is_notice;
     /* console.log($this.goodsInfo);*/
      getpersonInformation($this,data);
      getGoodsSpec($this,$this.group_ids,$this.activitys_id);
      if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {
      console.log('出错了');
    })
}
function getTopten($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/shop/getTopten",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {

      if (res.data.code == 1) {
        $this.data1=res.data.data;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function getDayNew($this){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  axios({
    url: "/super/api/Shop/dayNew",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token: token,
    }
  })
    .then(function(res) {

      $this.dataList=res.data.data.list;
      $this.datas=res.data.data;
      if (res.data.code == 1) {
        $this.data2=res.data.data.list;
        $this.dayTimeLists = data1.list;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function dayGoodList($this,page,id){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  axios({
    url: "/super/api/Shop/dayGoodList",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:page,
      new_id:id,
    }
  })
    .then(function(res) {
      $this.goodList=res.data.data.list;
      if (res.data.code == 1) {

      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function loadedNewGoods($this,loaded,id){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  $this.page++;
  axios({
    url: "/super/api/Shop/dayGoodList",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:$this.page,
      new_id:id,
    }
  })
    .then(function(res) {

      if (res.data.code == 1) {
        res.data.data.list.forEach((v) => {
          $this.articleList.push(v);
        });
        if ($this.page <= $this.data1.all_page) {
          $this.commendList = this.commendList.concat($this.articleList);
          $this.BOTTOM_DEFAULT_CONFIG.doneText = $this.BOTTOM_DEFAULT_CONFIG.pullText;
          loaded("done");
        } else {
          $this.BOTTOM_DEFAULT_CONFIG.doneText = "内容已全部展示";
          //结束刷新功能
          loaded("done");
          $this.loaded = true;
        }
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
      if (res.data.code == 1) {
        $this.data1=res.data.data;
      }else{

      }
    })
    .catch(function(res) {});
}
function preSale($this,page){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  axios({
    url: "/super/api/Goods/preSale",
    method: "post",
    data: {
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:page,
    }
  })
    .then(function(res) {
      $this.number=res.data.data.number;
      $this.dataList = res.data.data.list;
      if (res.data.code == 1) {
        $this.data2=res.data.data.list;
        $this.dayTimeLists = data1.list;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function getpreSale($this,page){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  page++;
  axios({
    url: "/super/api/Goods/preSale",
    method: "post",
    data: {
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:page,
    }
  })
    .then(function(res) {
      $this.dataList = res.data.data.list;
      $this.dataList = this.dataList.concat($this.dataList);
      $this.BOTTOM_DEFAULT_CONFIG.doneText = $this.BOTTOM_DEFAULT_CONFIG.pullText;
      loaded("done");
     /* if (res.data.code == 1) {
       /!* res.data.data.list.forEach((v) => {
          $this.articleList.push(v);
        });*!/
        if ($this.dataList != null || $this.dataList != '') {
          $this.dataList = this.dataList.concat($this.dataList);
          $this.BOTTOM_DEFAULT_CONFIG.doneText = $this.BOTTOM_DEFAULT_CONFIG.pullText;
          loaded("done");
        } else {
          $this.BOTTOM_DEFAULT_CONFIG.doneText = "内容已全部展示";
          //结束刷新功能
          loaded("done");
          $this.loaded = true;
        }
      }else{

      }*/
    })

    .catch(function(res) {});
}
function goodsGroup($this){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  axios({
    url: "/super/api/shop/newGroup",
    method: "post",
    data: {
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {
      $this.isNone=true;
      if (res.data.code == 1) {
        $this.dataList = res.data.data.list;
        $this.data2=res.data.data.list;
        $this.dayTimeLists = data1.list;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function getGroupgoods($this,beginTime,endTime){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  axios({
    url: "/super/api/shop/newGroupGoods",
    method: "post",
    data: {
      begin_time:beginTime,
      end_time:endTime,
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {
      $this.goodsList = res.data.data.list;
      if (res.data.code == 1) {
        $this.data2=res.data.data.list;
        $this.dayTimeLists = data1.list;
      }else{

      }
    })
    .catch(function(res) {});
}
function getJoinIn($this){
  var time = Date.parse(new Date())/1000;let token = getToken($this);
  axios({
    url: "/super/api/shop/getJoinIn",
    method: "post",
    data: {
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {

      if(res.data.code==1){
        $this.data=res.data.data;
        $this.money=res.data.data.data[0].guaranteed_amount;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function getCommen($this){
  let token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
    url: "/super/api/shop/commen",
    method: "post",
    data: {
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {

      if(res.data.code==1){
        $this.data=res.data.data;
        $this.money=res.data.data.data[0].guaranteed_amount;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function purchaseLimit($this,limiType){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/Shop/newpurchaseLimit",
    method: "post",
    data: {
      limit_type:limiType,
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token: token,
    }
  })
    .then(function(res) {
      $this.isNone=true;
      $this.dataList = res.data.data.list;
      $this.isNone=true;
      if (res.data.code == 1) {

        $this.data2=res.data.data.list;
        $this.dayTimeLists = data1.list;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function limitGoods($this,limitType){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/Shop/limitGoods",
    method: "post",
    data: {
      limit_id:limitType,
      page:1,
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {
      $this.goodsList = res.data.data.list;
      $this.goodsMes = res.data.data;
      if (res.data.code == 1) {
        $this.data2=res.data.data.list;
        $this.dayTimeLists = data1.list;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function loadedNewLimitGoods($this,loaded,limitId){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  $this.page++;
  axios({
    /*url: "/super/api/Shop/limitGoods",*/
    url: "/super/api/Shop/limitGoods",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:$this.page,
      limit_id:limitId,
    }
  })
    .then(function(res) {
      if (res.data.code == 1) {
     /*res.data.data.list.forEach((v) =>{
          $this.articleList.push(v);
        });*/
        let allPage = res.data.data.all_page;
        if ($this.page <= allPage) {
          $this.goodsList = $this.goodsList.concat(res.data.data.list);
          $this.BOTTOM_DEFAULT_CONFIG.doneText = $this.BOTTOM_DEFAULT_CONFIG.pullText;
          loaded("done");
        } else {
          $this.BOTTOM_DEFAULT_CONFIG.doneText = "内容已全部展示";
          //结束刷新功能
          loaded("done");
          $this.loaded = true;
        }
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
      if (res.data.code == 1) {
        $this.data1=res.data.data;
      }else{

      }
    })
    .catch(function(res) {});
}
function getpersonInformation($this,data){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/user/index",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {
      $this.isNone=true;
      $this.is_login=res.data.code
      $this.data1=res.data.data;
      if (res.data.code == 1) {
        var is_vip,sex;
        localStorage.setItem('balance',res.data.data.balance)
        if(res.data.data.is_vip){
          is_vip="是"
        }else{
          is_vip="否"
        }
        if(res.data.data.sex){
          sex="男"
        }else{
          sex="女"
        }
        ysf.on({
          'onload': function(){
            ysf.config({
              uid:res.data.data.user_no,
              data:JSON.stringify([
                  {"key":"real_name","label":"真实姓名", "value":res.data.data.user_name},
                  {"key":"mobile_phone", "label":"手机","value":res.data.data.user_phone},
                  {"index":1, "key":"sex", "label":"性别", "value":sex},
                  {"index":2, "key":"avatar","label":"头像","value":res.data.data.head_ico},
                  {"index":3, "key":"is_vip","label":"是否VIP","value":is_vip},
                  // {"index":4, "key":"reg_date", "label":"注册日期", "value":"2015-11-16"},
                  // {"index":5, "key":"last_login", "label":"上次登录时间", "value":"2015-12-22 15:38:54"},
                  // {"index":6, "key":"login_ip","label":"登录IP","value":"127.0.0.1"},
              ])
            });
            ysf.product({
              sendByUser: 0, // 是否由访客手动发送，1为是，其他参数为否
              show : 1, // 1为打开，其他参数为隐藏（包括非零元素）
              actionText: '发送链接', // 发送按钮文案
              actionTextColor: '#000000', // 发送按钮文案颜色（16进制格式）
              title : data.goods_name,
              desc : data.function,
              picture : data.goods_image,
              note : data.goods_no,
              url : window.location.href
            })
          }
        })
      }else if (res.data.code == -2) {
        ysf.on({
          'onload': function(){
            ysf.product({
              sendByUser: 0, // 是否由访客手动发送，1为是，其他参数为否
              show : 1, // 1为打开，其他参数为隐藏（包括非零元素）
              actionText: '发送链接', // 发送按钮文案
              actionTextColor: '#000000', // 发送按钮文案颜色（16进制格式）
              title : data.goods_name,
              desc : data.function,
              picture : data.goods_image,
              note : '',
              url : window.location.href
            })
          }
        })
        // 登录失效
        // fail($this);
      }
    })
    .catch(function(res) {});
}
/*查看订单列表*/
function getOrder($this,status){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/user/orderList",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:1,
      status:status,
    }
  })
    .then(function(res) {

      $this.isNone=true;
      if (res.data.code == 1) {
        $this.allCount = res.data.data.all_count;
        $this.data=res.data.data.list;
      }else if(res.data.code==-2){
        // $this.$toast(res.data.message);
        // fail($this);
      }
    })
    .catch(function(res) {});
};
function getGoodsByCid($this){
  $this.isNone=false;
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: "/super/api/Shop/getGoodsByCid",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
      page:$this.page,
      category_id:$this.category_id,
    }
  })
  .then(function(res) {
    if(res.data.code==1){
      $this.allPage=res.data.data.all_page;
      $this.guessLick=$this.guessLick.concat(res.data.data.list);
      $this.isNone=true;
      // $this.isNone=false;
    }else if (res.data.code == -2) {
      // 登录失效
      fail($this);
    }

  })
  .catch(function(res) {});
}
function getShopIndex($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url: "/super/api/shop/newindex",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function(res) {
      if (res.data.code == 1) {
        $this.data=res.data.data;
        $this.list1=res.data.data.today.info;
        $this.category_id=res.data.data.category[0].category_id;
        getpersonInformation($this)
        getGoodsByCid($this);
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function addressList($this){
  var time = Date.parse(new Date())/1000;
  var token= getToken($this)
  axios({
    url: "/super/api/user/addressList",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,

    }
  })
    .then(function(res) {
      if (res.data.code == 1) {
        $this.data=res.data.data;

        if(res.data.data.list.length>0){
          res.data.data.list.forEach((v,i)=>{
            $this.list.push({
              id:v.address_id,
              name:v.accept_name,
              tel:v.phone,
              address:v.big_address+v.address,
              smallAddress:v.address,
              area:v.area,
              is_default:v.is_default,
              first_id:v.province,
              second_id:v.city,
              third_id:v.area,
            })
          })
          $this.chosenAddressId=res.data.data.list[0].address_id
        }
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function(res) {});
}
function enjoy($this) {
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/Shop/wishList',
    method:'post',
    data:{
      page:$this.page,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      const data = res.data.data;
      $this.list = data.list;
      if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function addAddress($this,save){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/user/addAddress',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      first_id:$this.first_id,
      second_id:$this.second_id,
      third_id:$this.third_id,
      accept_name:save.name,
      phone:save.tel,
      address:save.addressDetail
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.$router.back(-1);
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }else{
        $this.$toast(res.data.message)
      }
    })
    .catch(function (res) {


    })
}
function editAddress($this,save){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/user/editAddress',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      first_id:$this.first_id,
      second_id:$this.second_id,
      third_id:$this.third_id,
      accept_name:save.name,
      phone:save.tel,
      address:save.addressDetail,
      address_id:$this.$route.query.addressId
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.$router.back(-1);
      }else  if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function deleteAddress($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/user/deleteAddress',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      address_id:$this.$route.query.addressId
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        localStorage.removeItem('address')
        $this.$router.back(-1)
      }else  if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function setDefaultAddress($this,id,item){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/user/setDefaultAddress',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      address_id:id
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        let address=item;
        localStorage.setItem('address',JSON.stringify(address));
        if($this.$route.query.type){
          $this.$router.go(-1)
        }

      }else  if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
//加入购物车
function joinChart($this,type,goodsId,chooseNum,specId){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/addCart',
    method:'post',
    data:{
      type:$this.types,
      activity_id:$this.activity_id,
      goods_id:goodsId,
      goods_num:chooseNum,
      spec_id:specId,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      if (res.data.code == -2){
        $this.$toast(res.data.message);
        fail($this)
      }else if(res.data.code == 1){
        const data = res.data;
        $this.mesChart = data.message;
        $this.$toast(res.data.message);
        $this.goodsInfo.cart_number=res.data.data.cart_number;
      }
    })
    .catch(function (res) {

    })
}
function cartList($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/goods/cartList',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      $this.isNone=true;
      if(res.data.code==1){
        $this.data=res.data.data;
      }else if (res.data.code == -2) {
      }
    })
    .catch(function (res) {

    })
}
function updateCart($this,type,cart_id){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/goods/updateCart',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      cart_id:cart_id,
      type:type
    }
  })
    .then(function (res) {
      if(res.data.code==1){

      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function delCart($this,cart_id){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/goods/delCart',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      cart_id:cart_id,
    }
  })
    .then(function (res) {
      if(res.data.code==1){

      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
//购买商品
function buyGoods($this,chooseNum,specId,groupType){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/order/beforeOrder',
    method:'post',
    data:{
      type:$this.types,
      goods_id:$this.goods_ids,
      spec_id:specId,
      goods_number:chooseNum,
      article_id:$this.article_id,
      limit_id:$this.limit_ids,
      group_type:groupType,
      group_id:$this.group_ids,
      join_id:$this.join_ids,
      cart_id:$this.cart_id,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      activity_id:$this.activity_id,
    }
  })
    .then(function (res) {
      if (res.data.code == -2){
        $this.$toast(res.data.message);
        fail($this)
      }else if(res.data.code == 1){
        const data = res.data;
        var comfirm1={
          type:$this.types,
          goods_id:$this.goods_ids,
          spec_id:specId,
          goods_number:chooseNum,
          article_id:$this.article_id,
          limit_id:$this.limit_ids,
          group_type:groupType,
          group_id:$this.group_ids,
          join_id:$this.join_ids,
          cart_id:$this.cart_id,
          time:time,
          device_id:$this._globe.device_id,
          version:$this._globe.version,
          platform:$this._globe.platform,
          token:token,
          activity_id:$this.activity_id,
        }
        // if(JSON.stringify(data.data.address)!="{}"){
          localStorage.setItem('returnArr', JSON.stringify(data));
          localStorage.setItem('comfirm',JSON.stringify(comfirm1));
          localStorage.setItem('activity',JSON.stringify($this.activity_id));
          $this.$router.push({
            path: '/order',
          })
        // }else{
        //   $this.$toast('请添加收货地址');
        // }

      }else{
        $this.$toast(res.data.message);
      }

    })
    .catch(function (res) {
      if (res.data.code == -2){
        fail($this)
      }
    })
}
//收藏/取消收藏商品
function ifLiked($this,type,goodsId){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/collectGoods',
    method:'post',
    data:{
      type:type,
      goods_id:goodsId,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      const data = res;
      $this.$toast(data.data.message);
      if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function userIndex($this){
  var time = Date.parse(new Date())/1000;
  var token=getToken($this);
  axios({
    url:'/super/api/user/index',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.data=res.data.data;
      }else{
        $this.$toast(res.data.message);
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function getExtract($this,loading){
  //获取token
  var token = getToken($this);
  axios({
      url: "/super/index/Spread/extract",
      method: "post",
      data: {
          token:token,
          // month:$this.year+''+$this.month,
      }
    })
  .then(function(res) {
      if (res.data.code == 1) {
          $this.data=res.data.data;
          // loading.close();
      }else{
          loading.close();
          $this.$cookie.set('token','',-1);
          if((window.android != null && typeof window.android != "undefined")||window.webkit){
              $this.getLogin()
          }else{
              fail($this)
          }
          //
      }
  })
  .catch(function(res) {});
}
function setPutforward($this){
  //获取token
  var token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
      url: "/super/api/user/withdraw",
      method: "post",
      data: {
          token:token,
          time:time,
          device_id:$this._globe.device_id,
          version:$this._globe.version,
          platform:$this._globe.platform,
          nickname:$this.name,
          truename:$this.username,
          account:$this.number,
          price:$this.money,
      }
    })
  .then(function(res) {
      if(res.data.code == 1){
          // loading.close();
          $this.$router.push({
            path:'/notecase'
          })
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this);
      }else{
        $this.$toast(res.data.message)
      }
  })
  .catch(function(res) {});
}
function withdrawInfo($this){
  //获取token
  var token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
      url: "/super/api/user/withdrawInfo",
      method: "post",
      data: {
          token:token,
          time:time,
          device_id:$this._globe.device_id,
          version:$this._globe.version,
          platform:$this._globe.platform,
          status:$this.status,
          page:$this.page
      }
    })
  .then(function(res) {

      if(res.data.code == 1){
          // loading.close();
          $this.data=res.data.data;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
  })
  .catch(function(res) {});
}
function fundRecord($this){
  //获取token
  var token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
      url: "/super/api/user/fundRecord",
      method: "post",
      data: {
          token:token,
          time:time,
          device_id:$this._globe.device_id,
          version:$this._globe.version,
          platform:$this._globe.platform,
          page:$this.page
      }
    })
  .then(function(res) {
      if(res.data.code == 1){
          // loading.close();
          $this.data=res.data.data;
          $this.list=$this.list.concat(res.data.data.list);
          $this.allPage=res.data.data.all_page;
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
  })
  .catch(function(res) {});
}
function getPayMethodo($this){
  //获取token
  var token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
      url: "/super/api/pay/getPayMethodo",
      method: "post",
      data: {
          token:token,
          time:time,
          device_id:$this._globe.device_id,
          version:$this._globe.version,
          platform:$this._globe.platform,
      }
    })
  .then(function(res) {

      if(res.data.code == 1){
          // loading.close();
          $this.data=res.data.data;

      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
  })
  .catch(function(res) {});
}
//获取支付方式
function getPayMethod($this,confirm){
  //获取token
  $this.token = getToken($this);
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:"/super/api/pay/getPayMethod",
    methods:'post',
    data:{
      token:token,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      time:time,
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        // $this.data = res.data.data;
        $this.radio= res.data.data.pay_id;
        $this.dataList = res.data.data.list;
        console.log(confirm)
        if (confirm){
          confirmOrder($this);
        } else{
        }
      }else if (res.data.code == -2) {
        // 登录失效
        fail($this);
      }
    })
    .catch(function (res) {

    })
}

function recharge($this){
  var token=getToken($this);
  var time= Date.parse(new Date())/1000;
  axios({
    url:'/super/api/user/recharge',
    method:'post',
    data:{
      token:token,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      time:time,
      price:$this.actual,
      pay_id:$this.radio,
    }
  })
  .then(function(res){
    if(res.data.code==1){
      if(res.data.data.pay_type==2){
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest', {
            "appId":res.data.data.wxpay_params.appId,     //公众号名称，由商户传入
            "timeStamp":res.data.data.wxpay_params.timeStamp,         //时间戳，自1970年以来的秒数
            "nonceStr":res.data.data.wxpay_params.nonceStr, //随机串
            "package":res.data.data.wxpay_params.package,
            "signType":"MD5",
            "paySign":res.data.data.wxpay_params.paySign,
          },
          function(res){
          if(res.err_msg == "get_brand_wcpay_request:ok" ){

          }else{
            // alert(res.err_msg+'..');

          }
        });
      }else if(res.data.data.pay_type==1){
        $this.aliPay=res.data.data.alipay_params;
      }else{
        $this.$emit('isPay',true)
      }
      $this.close();
    }else if (res.data.code == -2) {
      $this.$toast(res.data.message);
      fail($this);
    }
  })
  .catch(function(res){

  })
}
function getPay($this){
  var token=getToken($this);
  var time= Date.parse(new Date())/1000;
  axios({
    url:'/super/api/shop/getPay',
    method:'post',
    data:{
      token:token,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      time:time,
      pay_id:$this.radio,
      order_sn:$this.order_sn,
      wx_openid:localStorage.getItem('openid'),
    }
  })
  .then(function(res){
    if(res.data.code==1){
      if(res.data.data.pay_type==2){
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest', {
            "appId":res.data.data.wxpay_params.appId,     //公众号名称，由商户传入
            "timeStamp":res.data.data.wxpay_params.timeStamp,         //时间戳，自1970年以来的秒数
            "nonceStr":res.data.data.wxpay_params.nonceStr, //随机串
            "package":res.data.data.wxpay_params.package,
            "signType":"MD5",
            "paySign":res.data.data.wxpay_params.paySign,
          },
          function(res){
          if(res.err_msg == "get_brand_wcpay_request:ok" ){

          }else{
            // alert(res.err_msg+'..');

          }
        });
      }else if(res.data.data.pay_type==1){
        $this.aliPay=res.data.data.alipay_params;
      }else{
        $this.$emit('isPay',true)
      }

    }else if (res.data.code == -2) {
      $this.$toast(res.data.message);
      fail($this);
    }else if (res.data.code == -1){
      $this.$toast(res.data.message);
      $this.$router.push({
        path:'/myOrder'
      })
    }
  })
  .catch(function(res){

  })
}
//取消订单
function cancelOrder($this,type,orderNum){
  //获取token
  /*$this.token = getToken($this);*/
  let token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
    url:"/super/api/user/operateOrder",
    method:'post',
    data:{
      type:type,
      order_no:orderNum,
      token:token,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      time:time,
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.$emit('reload');
        $this.$toast(res.data.message);
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this);
      }
    })
    .catch(function (res) {
      if (res.data.code == -2){
        fail($this)
      }
    })
}
//订单详情
function orderDetail($this,orderNum){
  //获取token
  let token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
    url:"/super/api/user/orderInfo",
    method:'post',
    data:{
      order_no:orderNum,
      token:token,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      time:time,
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.data = res.data.data;
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this);
      }
    })
    .catch(function (res) {
      if (res.data.code == -2){
        fail($this)
      }
    })
}
//确认订单
function confirmOrder($this){
  var data=JSON.parse(localStorage.getItem('comfirm'));
  data['coupon_record_id']=$this.coupon_record_id;
  data['address_id']=$this.address_id;
  data['postscript']=$this.postscript;
  data['self_lifting']=$this.self_lifting;
  axios({
    url:"/super/api/order/confirmOrder",
    method:'post',
    data:data,
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.isGetMethod=false;
        $this.order_sn=res.data.data;
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this);
      }else if(res.data.code ==-1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function (res) {
    })
}
//待评价订单
function orderComment($this){
  //获取token
  let token = getToken($this);
  var time = Date.parse(new Date())/1000;
  axios({
    url:"/super/api/user/orderComment",
    method:'post',
    data:{
      page:1,
      token:token,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      time:time,
    }
  })
    .then(function (res) {
      if(res.data.code==1){
        $this.commentList = res.data.data.list;
        $this.commentCount=res.data.data.all_count;
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this);
      }
    })
    .catch(function (res) {
    })
}
//订单列表购买商品
//所有商品
function allGoods($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/shop/allGoods',
    method:'post',
    data:{
      type:$this.type,
      page:$this.page,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      category_id:$this.category_id,
    }
  })
    .then(function (res) {
      if(res.data.code == 1){
        var data = res.data;
        $this.goodList=$this.goodList.concat(data.data.list);
        $this.allPage=data.data.all_page;
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this)
      }

    })
    .catch(function (res) {
    })
}
//获取分类
function categoryList($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/Shop/categoryList',
    method:'post',
    data:{

      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      if(res.data.code == 1){
        $this.categoryList=res.data.data.list;
        $this.active1=[];
        $this.categoryList.length=$this.categoryList.length;
        if(res.data.data.list[0].info){
          $this.category_id=res.data.data.list[0].info[0].id
        }else{
          $this.category_id=res.data.data.list[0].id
        }
        getGoodsByCid($this)
      }else if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this)
      }

    })
    .catch(function (res) {
    })
}
function guessLike($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/shop/guessLike',
    method:'post',
    data:{
      page:1,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token
    }
  })
    .then(function (res) {
      const data = res.data.data;
      $this.list = data.list;
       if (res.data.code == -2) {
        $this.$toast(res.data.message);
        fail($this);
      }
    })
    .catch(function (res) {

    })
}
function club($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/home/index',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      const resData=res.data;
      if(resData.code==1){
        $this.list=resData.data.list;
      }else if (res.data.code == -2){
        fail($this);
      }
    })
    .catch(function (response) {
    })
}
//社區列表
function clubList($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url: '/super/api/home/getActicle',
    method: 'post',
    data: {
      category_id: $this.category_id,
      page: $this._globe.page,
      time:time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      token:token,
    }
  })
    .then(function (res) {
      const resData = res.data;
      if (resData.code == 1) {
        $this.commendList = resData.data.list;
        $this.reset = resData.data;
        $this.all_page = resData.data.all_page;
      }else if(res.data.code == -2){
        fail($this);
      }
    })
    .catch(function (response) {
    })
}
//社區上拉加載更多內容
function loadMoreclubList($this,loaded){
  $this.pages++;
  let token = getToken($this);
  if (loaded){
    var time = Date.parse(new Date())/1000;
    axios({
      url: '/super/api/home/getActicle',
      method: 'post',
      data: {
        category_id: $this.category_id,
        page: $this.pages,
        time: time,
        device_id: $this._globe.device_id,
        version: $this._globe.version,
        platform: $this._globe.platform,
        token:token,
      }
    }).then(response => {
      let data = response.data.data;
      $this.maxPage = data.all_page;//总页数
      if ($this.pages <= $this.maxPage) {
        $this.commendList = $this.commendList.concat(data.list);
        $this.BOTTOM_DEFAULT_CONFIG.doneText = $this.BOTTOM_DEFAULT_CONFIG.pullText;
        loaded("done");
      } else {
        $this.BOTTOM_DEFAULT_CONFIG.doneText = "内容已全部展示";
        //结束刷新功能
        loaded("done");
        loaded = true;
      }
    });
  }
}
function getHelp($this){
  var time = Date.parse(new Date())/1000;
  axios({
    url: "/super/api/index/getHelp",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform
    }
  })
    .then(function(response) {
      var resData = response.data;
      if (resData.code == 1) {
        $this.help_list = resData.data.help_list;
        $this.time=resData.data.online_service_time;
        $this.tel=resData.data.service_phone;
      } else if (resData.code == -2) {
        $this.getLogin();
      }
    })
    .catch(function(response) {
    });
}
function getHelpInfo($this){
  var time = Date.parse(new Date())/1000;
  axios({
    url: "/super/api/index/getHelpInfo",
    method: "post",
    data: {
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      page: $this.page,
      help_type_id: $this.help_type_id
    }
  })
    .then(function(response) {
      var resData = response.data;
      if (resData.code == 1) {
        $this.list = response.data.data.list;
        document.getElementsByTagName("title")[0].innerText =response.data.data.title;
        $this.tel= response.data.data.service_phone;
        $this.time=response.data.data.online_service_time;
      } else if (resData.code == -2) {
        $this.getLogin();
      }
    })
    .catch(function(response) {
      console.log(response);
    });
}
function setUse($this,n){
  var time = Date.parse(new Date())/1000;
  this.$http({
    url:'/super/api/index/setUse',
    method:'post',
    data:{
      time: time,
      device_id: $this._globe.device_id,
      version: $this._globe.version,
      platform: $this._globe.platform,
      type:n,
      help_id:$this.$route.query.help_id,
    }
  })
  .then(function(res){
    if(res.data.code==1){
      if(n==1){
        if($this.isUse1=='noUse'){
          $this.isUse1='useActive';
          $this.isUse2='noUse'
        }else if($this.isUse1=='useActive'){
        }
      }else if(n==2){
        if($this.isUse2=='noUse'){
          $this.isUse2='useActive';
          $this.isUse1='noUse';
        }else if($this.isUse1=='useActive'){
        }
      }
    }
    $this.isClick=false;

  })
  .catch(function(res){

  })
}
//获取商品规格
function getGoodsSpec($this,groupId,activityId){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/getSpec',
    method:'post',
    data:{
      group_id:$this.group_ids,
      limit_id:$this.limit_ids,
      goods_id:$this.goods_ids,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      activity_id:activityId,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.is_join_group=1;
        $this.respon = res.data.data;
        $this.spec = res.data.data.spec;
        $this.sku = res.data.data.sku;
        $this.storeNums = res.data.data.all_store_nums;
      }else if (res.data.code ==2){
        fail($this)
      }
    })
    .catch(function(res){

    })
}
//增加到货提醒
function addNotice($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/addNotice',
    method:'post',
    data:{
      goods_id:$this.goodsId,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.respon = res.data.data;
        $this.$toast(res.data.message);
        $this.code = res.data.code;
        $this.is_notice=1;

      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
//查看更多团购信息
function seeMore($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/groupbuying',
    method:'post',
    data:{
      goods_id:$this.goods_ids,
      time:time,
      page:1,
      type:2,
      limit_id:0,
      group_id:$this.group_ids,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.groupList = res.data.data.ret;
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
      }
    })
    .catch(function(res){

    })
}
function request(paras){
  var url = location.href;
  var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
  var paraObj = {}
  for (i=0; j=paraString[i]; i++){
    paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
  }
  var returnValue = paraObj[paras.toLowerCase()];
  if(typeof(returnValue)=="undefined"){
    return "";
  }else{
    return returnValue;
  }
}
//如你给出的地址可以这样
// var type = request("type");
// var id = request("id");

/*双十二活动页*/
function doubleTwelve($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/shop/doubleTwelve',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.respon = res.data.data;
        $this.dataList = $this.respon.list;
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
//获取订单的运费
function getOrderPrice($this,activity){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/order/getOrderPrice',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      type:$this.confirm.type,
      address_id:$this.address_id,
      coupon_record_id:0,//优惠券
      self_lifting:0,//自提
      goods_id:$this.confirm.goods_id,
      spec_id:$this.confirm.spec_id,
      goods_number:$this.confirm.goods_number,
      article_id:$this.confirm.article_id,
      limit_id:$this.confirm.limit_id,
      group_type:$this.confirm.group_type,
      group_id:$this.confirm.group_id,
      join_id:$this.confirm.join_id,
      cart_id:$this.confirm.cart_id,
      activity_id:activity,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.pay = res.data.data.pay_price;
        $this.address_id = res.data.data.address.address_id;
        $this.shipping_fee = res.data.data.shipping_fee.freight;
        console.log($this.address_id);
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        /*$this.$toast(res.data.message);*/
      }
    })
    .catch(function(res){

    })
}
//获取中奖信息列表
function winnersInformation($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/winnersInformation',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      activity_category_id:$this.activity_category_id,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.data = res.data.data;
        console.log($this.data);
        var Li = document.getElementsByTagName("li");
        $this.data.forEach((value,index)=>{
          if (value.is_user == 1) {
            $this.data.splice(index, 1);
            $this.data.unshift(value);
          }
        })
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
//获取首页弹出图
function getAlertImg($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/shop/getAlertPage',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        console.log(res);
        $this.show = res.data.data.is_open;
        $this.alertRespon = res.data.data;
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
//抽奖
function chouPrize($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  $this.isLoading=false;
  axios({
    url:'/super/api/goods/winning',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){

      if(res.data.code==1){
        $this.ifOpenPrize.count--;
        setTimeout(()=>{
          $this.isXuanzhuan=false;

        },1000)
        $this.chouPrize = res.data.data;
        $this.gift_id = res.data.data.winning_id;
        $this.getPrizeInfo = res.data;
        $this.priceImg=res.data.data.image;
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
        $this.isXuanzhuan=false;
      }
    })
    .catch(function(res){

    })
}
/*领奖*/
function lingPrize($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/accpetGift',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      gift_id:$this.gift_id,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.$toast(res.data.message);
        $this.lingPrize = res.data.data;
        console.log($this.lingPrize);
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.show = 0;
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
/*是否开启抽奖*/
function ifOpenPrize($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/openWinnning',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      $this.isNone=true;
      if(res.data.code==1){

        $this.ifOpenPrize = res.data.data;
        $this.show = res.data.data.is_open;
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
/*获取用户足迹*/
function getHistory($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/user/getLook',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      page:$this.page,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.data = res.data.data.list;
        console.log($this.data);
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
/*黑卡会员*/
function getUserCard($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/shop/getUserCard',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      page:$this.page,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.data = res.data.data;
        $this.image = res.data.data.image;
        $this.card = res.data.data.card;
        $this.discount = res.data.data.discount;
        $this.goods_list = res.data.data.goods_list;
        console.log($this.data);
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
function rebateOrder($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/user/rebateOrder',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
      page:$this.page,
      status:$this.active,
    }
  })
    .then(function(res){
      $this.isNone=true;
      if(res.data.code==1){
        $this.list=$this.list.concat(res.data.data.list);
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
/*双旦是否开启抽奖*/
function ifChrisOpenPrize($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/goods/openWinnning',
    method:'post',
    data:{
      type:$this.type,
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      $this.isNone=true;
      if(res.data.code==1){
        $this.ifOpenPrize = res.data.data;
        $this.ifOpenPrize.winners.forEach((value,index)=>{
          if (value.is_user == 1) {
            $this.ifOpenPrize.winners.splice(index, 1);
            $this.ifOpenPrize.winners.unshift(value);
          }
        })
        $this.show = res.data.data.is_open;
        $this.winners = res.data.data.winners;
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}
function selfOrderIndex($this){
  axios({
    url:'/super/api/self_order/index',
    method:'post',
    data:{
      page:$this.page,
      keys:$this.keys,
      status:$this.status,
    }
  })
    .then(function(res){
      $this.isNone=true;
      if(res.data.code==1){
        if(res.data.data.length>0){
          $this.data.list=$this.data.list.concat(res.data.data);
        }else{
          $this.isAll=true;
          console.log($this.isAll);
        }
        
      }else{
        $this.$router.push({
          path: '/mentionLogin'
        })
      }
    })
    .catch(function(res){
    })
}
function selfOrderDetails($this){
  axios({
    url:'/super/api/self_order/selfOrderDetails',
    method:'post',
    data:{
      order_no:$this.order_no,
    }
  })
    .then(function(res){
      $this.isNone=true;
      if(res.data.code==1){
        $this.data=res.data.data;
      }else{
        $this.$router.push({
          path: '/mentionLogin'
        })
      }
    })
    .catch(function(res){
    })
}
function selfLiftingDetails($this){
  axios({
    url:'/super/api/self_order/selfLiftingDetails',
    method:'post',
    data:{
      order_no:$this.order_no,
      type:$this.type,
    }
  })
    .then(function(res){
      $this.isNone=true;
      if(res.data.code==1){
        $this.data=res.data.data;
      }else{
        $this.$router.push({
          path: '/mentionLogin'
        })
      }
    })
    .catch(function(res){
    })
}
function distribution($this){
  $this.isLoading=false;
  axios({
    url:'/super/api/self_order/distribution',
    method:'post',
    data:{
      order_no:$this.order_no,
      type:$this.type,
      order_goods:JSON.stringify($this.order_goods)
    }
  })
    .then(function(res){
      $this.isLoading=true;
      if(res.data.code==1){
        $this.$router.go(-1)
      }else if(res.data.code==-1){
        // $this.$router.push({

        // })
      }else{
        $this.$toast(res.message)
      }
    })
    .catch(function(res){
    })
}
function checkLogin($this){
  $this.isLogin=false
  axios({
    url:'/super/api/hlogin/check_login',
    method:'post',
    data:{
      account:$this.account,
      password:$this.password,
    }
  })
    .then(function(res){
      $this.isLogin=true;
      if(res.data.code==1){
        $this.$router.push({
          path: '/mentionList'
        })
      }else if(res.data.code==-1){
        $this.$toast(res.message)
      }else{
        $this.$toast(res.message)
      }
    })
    .catch(function(res){
    })
}

/*/!*收藏，取消收藏文章*!/
function collectArticle($this){
  var time = Date.parse(new Date())/1000;
  let token = getToken($this);
  axios({
    url:'/super/api/Home/collect',
    method:'post',
    data:{
      time:time,
      device_id:$this._globe.device_id,
      version:$this._globe.version,
      platform:$this._globe.platform,
      token:token,
    }
  })
    .then(function(res){
      if(res.data.code==1){
        $this.data = res.data.data;
        console.log($this.data);
      }else if (res.data.code ==2){
        fail($this)
      }else if (res.data.code == -1){
        $this.$toast(res.data.message);
      }
    })
    .catch(function(res){

    })
}*/
export default {
  ifChrisOpenPrize,
  getUserCard,
  getHistory,
  ifOpenPrize,
  lingPrize,
  chouPrize,
  getAlertImg,
  winnersInformation,
  getOrderPrice,
  doubleTwelve,
  loadMoreclubList,
  seeMore,
  getGoodsSpec,
  clubList,
  club,
  getCode,
  getFollowDetail,
  getRecommendArticle,
  loadedRecommendArticle,
  getProductsDetail,
  getTopten,
  getDayNew,
  dayGoodList,
  loadedNewGoods,
  preSale,
  getpreSale,
  goodsGroup,
  getGroupgoods,
  getJoinIn,
  getCommen,
  purchaseLimit,
  limitGoods,
  loadedNewLimitGoods,
  getShopIndex,
  getpersonInformation,
  getOrder,
  getGoodsByCid,
  addressList,
  getLogin,
  hotSearchTopTen,
  searchGoods,
  fullTextSearch,
  enjoy,
  addAddress,
  editAddress,
  deleteAddress,
  addNotice,
  setDefaultAddress,
  joinChart,
  cartList,
  updateCart,
  delCart,
  userIndex,
  getExtract,
  setPutforward,
  buyGoods,
  ifLiked,
  withdrawInfo,
  getPayMethodo,
  getPayMethod,
  recharge,
  cancelOrder,
  orderDetail,
  getPay,
  confirmOrder,
  orderComment,
  allGoods,
  categoryList,
  getGoodsByCid,
  guessLike,
  getHelp,
  getHelpInfo,
  setUse,
  fundRecord,
  rebateOrder,
  selfOrderIndex,
  selfOrderDetails,
  selfLiftingDetails,
  distribution,
  checkLogin,
};
